package utility;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.SQLException;

public class connections
{
	public static String oracleUser = "azienda";
	public static String oraclePwd  = "azienda";
	public static Connection conn = null;
	public static Statement st = null;
	public static String driver;
	public static String oracle;
	public static String user,type,matr,cogn,pwd,nome,cognome,email,matricola,tipologia; 
	
	public static Connection getConnection() throws SQLException,ClassNotFoundException
	{
		driver = "oracle.jdbc.driver.OracleDriver";
		oracle = "jdbc:oracle:thin:@localhost:1521:xe"; 
		
		if (conn==null||conn.isClosed())
		{
			System.out.println("CREAZIONE CONNESSIONE...");
			Class.forName(driver);
			conn = DriverManager.getConnection(oracle, oracleUser, oraclePwd);
			System.out.println("Connessine creata");
			st = conn.createStatement();
		}
		return conn;
	}
	
	public static Statement getStatement() throws SQLException,ClassNotFoundException
	{
		conn=getConnection();
		st=conn.createStatement();
		return st;
	}
	public static void closeConnection() throws SQLException
	{
		st.close();
		conn.close();
	}
	
	public static String doubleQuota(String text)
	{
		String out;
		out=text.replace("'", "''");
		return out;
	}
	
	public static String singleQuota(String text)
	{
		String out;
		out=text.replace("''", "'");
		return out;
	}
	
}